package com.sec.etech.bpm.plugin.nodecontrol.context;

import com.alibaba.fastjson.JSONObject;
import com.sec.etech.bpm.plugin.nodecontrol.def.EtechNodeControlPluginDef;
import com.sec.etech.bpm.plugin.nodecontrol.executer.EtechNodeControlPluginExecutor;
import org.openbpm.base.core.util.JsonUtil;
import org.openbpm.bpm.api.engine.plugin.runtime.RunTimePlugin;
import org.openbpm.bpm.engine.plugin.context.AbstractUserCalcPluginContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

@Component
@Scope("prototype")
public class EtechNodeControlPluginContext extends AbstractUserCalcPluginContext<EtechNodeControlPluginDef> {

    @Override
    public String getDescription() {
        EtechNodeControlPluginDef pluginDef = getBpmPluginDef();
        if(pluginDef==null){
            return "";
        }
        return "控制编号："+pluginDef.getNodeControl();
    }

    @Override
    public Class<? extends RunTimePlugin> getPluginClass() {
        return EtechNodeControlPluginExecutor.class;
    }

    @Override
    public String getTitle() {
        return "节点控制编号";
    }

    @Override
    protected EtechNodeControlPluginDef parseJson(JSONObject pluginJson) {
        EtechNodeControlPluginDef pluginDef = getBpmPluginDef();
        String nodeControl = JsonUtil.getString(pluginJson, "nodeControl");
        pluginDef.setNodeControl(nodeControl);
        return pluginDef;
    }

}
